package com.wanlian.router.ui.integral;

import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.view.View;
import android.widget.TextView;

import com.smart.android.ui.BaseActivity;
import com.wanlian.router.R;
import com.wanlian.router.bean.IntegralTotal;
import com.wanlian.router.net.NetWorkingClient;
import com.wanlian.router.net.ResponseData;
import com.wanlian.router.net.internal.INetCallBack;
import com.wanlian.router.storage.AppData;

import java.util.List;
import java.util.Locale;

import butterknife.BindView;

/**
 * Created by Hyu on 2018/8/29.
 * Email: fvaryu@qq.com
 */
public class IntegralMallActivity extends BaseActivity {

    @BindView(R.id.tv_score)
    TextView tv_score;

    @Override
    protected int layout() {
        return R.layout.activity_integral_mall;
    }

    @Override
    public void initUI() {
        super.initUI();
        setTitle("兑换电信充值卡");

        setNextText("我的卡券");
        setNextColor(R.color.color_blue);
        setNextClickLisener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                redirectActivity(TelecomCardActivity.class);
            }
        });
    }

    @Override
    public void initData() {
        super.initData();

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.fragment, IntegralMallFragment.newInstance(), "mall")
                .commit();

        NetWorkingClient.getInstance().queryIntegral(getActivity(),0, new INetCallBack<List<IntegralTotal> >() {
            @Override
            public void onFinish(ResponseData response, @Nullable List<IntegralTotal>  integralTotals) {
                if (response.isSuccess()) {

                    if (integralTotals != null && integralTotals.size() > 0) {
                        IntegralTotal integralTotal = integralTotals.get(0);
                        SpannableString ss = new SpannableString(String.format(Locale.getDefault(),"您当前可兑换的积分额度为：%f积分",integralTotal.getDscore()));
                        ss.setSpan(new ForegroundColorSpan(getColorById(R.color.color_blue)), 13, ss.length() - 2, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);

                        tv_score.setText(ss);
                    }
                }else {
                    showToast(response.getMessage());
                }
            }
        });

    }
}
